

import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter_my_web/bean/request/up_file_to_res_request.dart';
import 'package:flutter_my_web/bean/response/nginx_get_file_json_response.dart';
import 'package:flutter_my_web/utils/Utils.dart';
import 'package:get/get.dart';

class FilePageController extends GetMaterialController{
  List<NginxGetFileJsonResponse> list = [];
  String curPath = "";
  @override
  Future<void> onInit() async {
    super.onInit();
    getData();
  }


  itemAction(NginxGetFileJsonResponse e){
    if(e.isDirectory){
      getDirectory(e.name!);
    }else{
      Clipboard.setData(ClipboardData(text: '${e.urlPath}'));
      showSnackBar("复制地址到剪切板~");
    }
  }
  updateFiles(List<File> files) async {
    UpFileToResRequest bean = UpFileToResRequest();
    bean.savedir = "/root/res"+curPath;
    bean.file = files;
    // var res = await FileManagerApi().upFileToRes(bean);
    // if (res.status!="1"){
    //   Get.snackbar("","请求失败：${res.errmessage}");
    // }else{
    //   Get.snackbar("","提交成功");
    // }
    getData();
  }

  getData() async {
    // list = await FileManagerApi().getFiles(curPath);
    refresh();
  }
  getDirectory(String directory){
    curPath = curPath+"/"+directory;
    if(curPath=="/"){
      curPath = "";
    }
    getData();
  }
  backDirectory(){
    if(curPath=="/"||curPath==""){
      curPath = "";
      getData();
      return;
    }
    curPath = File(curPath).parent.path;
    if(curPath=="/"){
      curPath = "";
    }
    getData();
  }

}